package top.oneit.jdownload.test;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;

import java.io.File;
import java.net.URI;

/**
 * @author lingkang
 * @date 2021/12/11
 */
public class MyMusic01 extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        File file = new File("C:\\Users\\Administrator\\Desktop\\塞壬唱片-MSR,BaoUner - 生命流.mp3");
        URI uri = file.toURI();
        System.out.println(uri);

        Media media = new Media(uri.toString());
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        mediaPlayer.setAutoPlay(true);
        MediaView mediaView = new MediaView(mediaPlayer);

        // 可以使用按钮控制
        //mediaPlayer.play();
        primaryStage.setScene(new Scene(new AnchorPane(mediaView)));
        primaryStage.show();
    }

    public static void main(String[] args) throws Exception {
        launch(args);
    }
}
